home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ANIVGA.ZIP / EXAMPLE5.PAS < prev    next >
Pascal/Delphi Source File  |  1992-08-17  |  3KB  |  102 lines

  1. PROGRAM Example5;
  2.  
  3. {Demonstrates how to use an image as a scrolling background: the program will}
  4. {load 5 tiles: a black one to be used for the surrounding image, and an image}
  5. {2x2 tiles which is used to build the real background "image"}
  6.  
  7. {$X+} {to ignore results of functions}
  8. USES ANIVGA,CRT;
  9. CONST TileName1='black.COD';     {1 black tile}
  10.       TileName2='aegypten.COD';  {4 tiles, captured from Win3.1}
  11.       tiles_per_row=2;           {These are the proportions of }
  12.       tiles_per_column=2;        {the above 4 tile file: 2x2!  }
  13.       SpriteName='flower.COD';
  14.       FlowerLoadNumber=1;        {load number for sprite}
  15.       Flower1=0;                 {sprite number}
  16.       Flower2=1;                 {another one  }
  17.       ch:Char=#0;
  18.  
  19. PROCEDURE Init;
  20. {Note that the tiles do not have to be actually loaded into memory! This}
  21. {procedure pastes just _numbers_, not tiles - they will be loaded later!}
  22. VAR gx,gy,count:INTEGER;
  23.     Row:WORD;
  24. BEGIN
  25.  XTiles:=0; YTiles:=0;
  26.  SetBackgroundMode(scrolling);
  27.  SetBackgroundScrollRange(50,50,300,100);
  28.  
  29.  {paste tiles into this background, using circular enumeration 1,2,3,4,1,...}
  30.  count:=0; Row:=0;
  31.  gy:=BackY1;
  32.  REPEAT
  33.   gx:=BackX1;
  34.   REPEAT
  35.    PutTile(gx,gy,succ(count + (Row MOD tiles_per_column)*tiles_per_row));
  36.    inc(count); count:=count MOD tiles_per_row;
  37.    inc(gx,16);
  38.   UNTIL gx>BackX2;
  39.   inc(Row); {or: Row:=(Row+1) MOD tiles_per_row}
  40.   inc(gy,16);
  41.  UNTIL gy>BackY2;
  42.  
  43.  {load sprite:}
  44.  IF loadSprite(SpriteName,FlowerLoadNumber)=0
  45.   THEN BEGIN
  46.         WRITELN('Couldn''t access file '+SpriteName+' : '+GetErrorMessage);
  47.         halt(1)
  48.        END;
  49. END;
  50.  
  51. BEGIN
  52.  Init; {set up tile organization}
  53.  InitGraph;
  54.  LoadTile(TileName1,0); {load the black tile as tile #0 = surrounding pattern}
  55.  IF Error<>Err_None
  56.   THEN BEGIN
  57.         CloseRoutines;
  58.         WRITELN('Couldn''t access file '+TileName1+' : '+GetErrorMessage);
  59.         halt(1)
  60.        END;
  61.  LoadTile(TileName2,1); {load the 4 tiles as tile #1..4 = inner picture}
  62.  IF Error<>Err_None
  63.   THEN BEGIN
  64.         CloseRoutines;
  65.         WRITELN('Couldn''t access file '+TileName2+' : '+GetErrorMessage);
  66.         halt(1)
  67.        END;
  68.  
  69.  SetCycleTime(0); {animation as fast as possible}
  70.  
  71.  SpriteN[Flower1]:=FlowerLoadNumber;
  72.  SpriteX[Flower1]:=0;
  73.  SpriteY[Flower1]:=0;
  74.  SpriteN[Flower2]:=FlowerLoadNumber;
  75.  SpriteX[Flower2]:=100;
  76.  SpriteY[Flower2]:=100;
  77.  
  78.  Animate;
  79.  REPEAT
  80.   IF Hitdetect(Flower1,Flower2) THEN BEGIN sound(1000); delay(5); nosound END;
  81.   if KeyPressed
  82.    THEN BEGIN
  83.          WHILE KeyPressed DO ch:=Upcase(ReadKey);
  84.          CASE ch OF
  85.           'I':dec(SpriteY[Flower1]);  {change position of sprite with I,J,K,M}
  86.           'J':dec(SpriteX[Flower1]);
  87.           'K':inc(SpriteX[Flower1]);
  88.           'M':inc(SpriteY[Flower1]);
  89.           'E':dec(StartVirtualY,10);  {change position of whole scene with}
  90.           'S':dec(StartVirtualX,10);  {E,S,D,X}
  91.           'D':inc(StartVirtualX,10);
  92.           'X':inc(StartVirtualY,10);
  93.          END;
  94.          IF POS(ch,'IJKMESDX')>0 THEN Animate; {=only if something changed}
  95.         END;
  96.  
  97.  UNTIL (ch='Q') OR (ch=#27);  {"Q" or ESC to quit}
  98.  
  99.  CloseRoutines;
  100.  
  101. END.
  102.